package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RecordPerson;
import com.ruoyi.system.service.IRecordPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卷内目录Controller
 *
 * @author admin
 * @date 2022-02-20
 */
@RestController
@RequestMapping("/system/person")
public class RecordPersonController extends BaseController {
    @Autowired
    private IRecordPersonService recordPersonService;

    /**
     * 查询卷内目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:person:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordPerson recordPerson) {
        startPage();
        List<RecordPerson> list = recordPersonService.selectRecordPersonList(recordPerson);
        return getDataTable(list);
    }

    /**
     * 导出卷内目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:person:export')")
    @Log(title = "卷内目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordPerson recordPerson) {
        List<RecordPerson> list = recordPersonService.selectRecordPersonList(recordPerson);
        ExcelUtil<RecordPerson> util = new ExcelUtil<RecordPerson>(RecordPerson.class);
        util.exportExcel(response, list, "卷内目录数据");
    }

    /**
     * 获取卷内目录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:person:query')")
    @GetMapping(value = "/{personId}")
    public AjaxResult getInfo(@PathVariable("personId") Long personId) {
        return AjaxResult.success(recordPersonService.selectRecordPersonByPersonId(personId));
    }

    /**
     * 新增卷内目录
     */
    @PreAuthorize("@ss.hasPermi('system:person:add')")
    @Log(title = "卷内目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordPerson recordPerson) {
        return toAjax(recordPersonService.insertRecordPerson(recordPerson));
    }

    /**
     * 修改卷内目录
     */
    @PreAuthorize("@ss.hasPermi('system:person:edit')")
    @Log(title = "卷内目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordPerson recordPerson) {
        return toAjax(recordPersonService.updateRecordPerson(recordPerson));
    }

    /**
     * 删除卷内目录
     */
    @PreAuthorize("@ss.hasPermi('system:person:remove')")
    @Log(title = "卷内目录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{personIds}")
    public AjaxResult remove(@PathVariable Long[] personIds) {
        return toAjax(recordPersonService.deleteRecordPersonByPersonIds(personIds));
    }
}
